home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Object.h
-
- Contains: *** put contents here ***
-
- Written by: Bruce Horn, Steve Capps, Larry Kenyon, John Meier, scott douglass, Darin Adler,
- Paul Mercer, Bryan Stearns, Dave Owens
-
- Andy Nicholas
-
- Copyright: © 1988-1995 by Apple Computer, Inc., all rights reserved.
-
- <5> 6/23/95 ga
- */
-
- #ifndef Object_h
- #define Object_h
-
- // #include "ClassIDs.h"
-
- #ifndef REZ
-
- #include "Debug.h"
-
- //
- // Types.h is needed for definition of "Boolean"
- //
- #include <Types.h>
-
- class TPropertyDescription;
-
- //========================================================================================
- // CLASS TClassPropertyInfo
- //========================================================================================
-
- class TClassPropertyInfo
- {
- public:
- Boolean PropertyExists(UInt32 propertyName) const;
- const TPropertyDescription* DescriptionOfProperty(UInt32 propertyName) const;
- SInt32 NumberOfProperties() const;
- const TPropertyDescription* DescriptionOfNthProperty(SInt32 propertyNumber) const;
-
- public:
- SInt32 fPropertyCount;
- TPropertyDescription* fArrayOfPropertyIdentifiers;
- };
-
- //========================================================================================
- // CLASS TClassData
- //========================================================================================
-
- class TClassData
- {
- public:
- #ifdef DEBUG
- char* fClassName; // In debug builds, the name of this class
- #endif
- UInt32 fObjectClass; // The object class is the Object-Support-Library class for this class
- UInt32 fClassID; // The class ID is used to partition the resource-ID/property ID space
- UInt32 fObjectSize; // The size of the class that this class data describes
- TClassData* fSuperClass; // A pointer to the superclass' class data
- TClassPropertyInfo fClassPropertyInfo; // A table that describes the properties for this class
-
- public:
- UInt32 ObjectClass() const { return fObjectClass; }
- UInt32 ClassID() const { return fClassID; }
- UInt32 ObjectSize() const { return fObjectSize; }
-
- const TClassData* SuperClass() const { return fSuperClass; }
- const TClassPropertyInfo& ClassPropertyInfo() const { return fClassPropertyInfo; }
- };
-
-
- //
- // Backwards compatability (don't use these)
- //
- #if 0
-
- #define DECLAREOBJECT(className) \
- static TClassData fClassData; \
- virtual const TClassData* ClassData() const
-
- #ifdef DEBUG
-
- #define IMPLEMENTOBJECT(className, classID, signature, superclass) \
- const TClassData* className::ClassData() const { return &fClassData; } \
- TClassData className::fClassData = {#className, 0, classID, sizeof(className), &superclass::fClassData, {0, nil} }
-
- #else
-
- #define IMPLEMENTOBJECT(className, classID, signature, superclass) \
- const TClassData* className::ClassData() const { return &fClassData; } \
- TClassData className::fClassData = {0, classID, sizeof(className), &superclass::fClassData, {0, nil} }
-
- #endif
- #endif
-
- //
- // Classes that do not define additonal properties use these
- // versions of the defines to save a little memory
- //
- #define DeclareSmallClassData(className, superclass) \
- static TClassData fClassData; \
- typedef superclass Inherited; \
- virtual const TClassData* ClassData() const
-
- #ifdef DEBUG
-
- #define ImplementSmallClassData(className, classID) \
- const TClassData* className::ClassData() const { return &fClassData; } \
- TClassData className::fClassData = {#className, 0, classID, sizeof(className), &className::Inherited::fClassData, {0, nil} }
-
- #else
-
- #define ImplementSmallClassData(className, classID) \
- const TClassData* className::ClassData() const { return &fClassData; } \
- TClassData className::fClassData = {0, classID, sizeof(className), &className::Inherited::fClassData, {0, nil} }
-
- #endif
-
-
- class TObject;
- class TBehavior;
-
- //========================================================================================
- // CLASS TCanReceiveDeleteNotification
- //
- // See comment with RegisterForDeleteNotification, below
- //========================================================================================
-
- class TCanReceiveDeleteNotification
- {
- public:
- virtual void ItemBeingDeleted(const TObject*) = 0;
- };
-
- //
- // Use with RegisterForDeleteNotification
- //
- enum
- {
- kUnregisterForDeleteNotification = 0,
- kRegisterForDeleteNotification
- };
-
- //========================================================================================
- // CLASS TObject
- //========================================================================================
-
- class TObject
- {
- #ifdef DEBUG
- private:
- //
- // This data is redundant, because it is available by way of
- // the virtual method ClassData(). We include it here in debug
- // builds so that we can find this information with greater
- // ease if we dump memory.
- //
- SInt32 fSignature;
- const TClassData* fClassDataPtr;
-
- void SetupObjectDebugInfo();
- #endif
-
- public:
- //
- // Most classes will use the DeclareClassData macro instead of
- // explicitly declaring their class data. TObject cannot use
- // the macros, though, as it has no superclass.
- //
- static TClassData fClassData;
- virtual const TClassData* ClassData() const;
-
- #ifdef DEBUG
- TObject() : fSignature(0), fClassDataPtr(nil) {}
- #endif
- virtual ~TObject();
-
- //
- // TObjects may be cloned; override 'CloneOwnedObjects'
- // and clone any memory blocks owned by the derived class
- //
- TObject* Clone();
- virtual void CloneOwnedObjects();
-
- //
- // TObjects have class data that may be inspected
- //
- SInt32 ClassID() const;
- UInt32 ObjectSize() const;
- Boolean DerivedFrom(SInt32 cast) const;
-
- //
- // If SortOrder and Key are overridden, then a list of
- // TObjects may be sorted
- //
- virtual Boolean SortOrder(const TObject*, void*) const;
- virtual SInt32 Key() const;
-
- //
- // Call RegisterForDeleteNotification if you (a TObject-derived class)
- // would like to be informed when this object is deleted. RegisterForDeleteNotification
- // will return 'true' if this object is capable of this notification.
- //
- // ItemBeingDeleted will be called on the object that was registered when
- // this item is deleted.
- //
- // For example:
- //
- // TCanReceiveDeleteNotification* object1;
- // TObject* object2;
- //
- // //
- // // Tell object2 that object1 would like to be notified
- // // when object2 is deleted
- // //
- // object2->RegisterForDeleteNotification(object1);
- //
- // delete object2;
- //
- // causes: object1->ItemBeingDeleted(object2);
- //
- virtual Boolean RegisterForDeleteNotification(TCanReceiveDeleteNotification*, Boolean shouldRegister);
-
- //
- // Behavior support:
- //
- // It is not possible to add a behavior to a plain TObject because
- // there is no storage for it. Subclasses may override FirstBehavior and
- // SetFirstBehavior in order to allow behaviors to be added to them.
- //
- virtual TBehavior* FirstBehavior() const;
- virtual void SetFirstBehavior(TBehavior* firstBehavior);
-
- TBehavior* FirstBehaviorOfClass(SInt32 classID) const;
-
- void AddBehavior(TBehavior* behavior);
- void RemoveBehavior(TBehavior* behavior);
-
- //
- // A few of our friends
- //
- friend Boolean operator==(const TObject&, const TObject&); // compares Key()s
- friend Boolean operator<(const TObject&, const TObject&); // compares Key()s
- };
-
- #ifndef DEBUG
-
- //
- // These methods are not inlined in debug builds so that
- // they can set up the debugging information for the object when they
- // are first called.
- //
- inline SInt32 TObject::ClassID() const { return ClassData()->ClassID(); }
- inline UInt32 TObject::ObjectSize() const { return ClassData()->ObjectSize(); }
-
- #endif
-
- #endif // REZ
- #endif // Object_h
-
-